package com.pashanhoo.netty.nio.channel;

import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author 胡庆安
 * @version V1.0
 * @Package com.pashanhoo.netty.nio.channel
 * @date 2020/11/4 17:11
 * @Copyright © 2010-2020 爬山虎科技（扬州）股份有限公司
 */
public class NIOFileChannel01 {
    public static void main(String[] args) throws IOException {
        String str = "我是javaTO神";
        FileOutputStream fileOutputStream = new FileOutputStream("d:\\file.txt");
        //通过文件输出流获取对应的文件channel
        FileChannel channel = fileOutputStream.getChannel();

        //创建缓冲区
        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
        byteBuffer.put(str.getBytes());
        byteBuffer.flip();
        channel.write(byteBuffer);
    }
}
